$(function() {
	$('#vue_vm_list').hide();
	$('#startYear').val('2017');
	$('#startMonth').val('1');
	$('#startDay').val('1');
});

function getMealsCostRecordSum(baseMealsCostRecordForms) {
	var totalMoney = 0;
	for(var j=0; j<baseMealsCostRecordForms.length; j++) {
		var payMoney = baseMealsCostRecordForms[j].payMoney;
		var quantity = baseMealsCostRecordForms[j].quantity;
		totalMoney += parseFloat((payMoney*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
	}
	
	return totalMoney;
}

function getMealsCostRecordTotal(todos) {
	var totalMoney = 0;
	for(var i=0; i<todos.length; i++) {
		for(var j=0; j<todos[i].baseMealsCostRecordForms.length; j++) {
			var payMoney = todos[i].baseMealsCostRecordForms[j].payMoney;
			var quantity = todos[i].baseMealsCostRecordForms[j].quantity;
			totalMoney += parseFloat((payMoney*quantity).toFixed(2)); //parseFloat必不可少，不然，js会把toFixed的结果当作字符串处理。
		}
	}
	
	return totalMoney;
}

function mealsCostRecord_findByMonth() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var year = $('#year').val();
	var month = $('#month').val();
	
	if(isEmpty(year)) {
		alert('请输入年');
		return;
	}
	if(isEmpty(month)) {
		alert('请选择月');
		return;
	}
	
	find_basic_by_json(path+'/mealsCostRecord/findByMonth', {month: getStandardMonth(year, month)}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getMealsCostRecordTotal:function(todos) {
					return getMealsCostRecordTotal(todos);
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function mealsCostRecord_findByDay() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var year = $('#year').val();
	var month = $('#month').val();
	var day = $('#day').val();
	
	if(isEmpty(year)) {
		alert('请输入年');
		return;
	}
	if(isEmpty(month)) {
		alert('请选择月');
		return;
	}
	if(isEmpty(day)) {
		alert('请选择日');
		return;
	}
	
	find_basic_by_json(path+'/mealsCostRecord/findByDay', {day: getStandardDay(year, month, day)}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getMealsCostRecordSum:function(baseMealsCostRecordForms) {
					return getMealsCostRecordSum(baseMealsCostRecordForms);
				},
				getMealsCostRecordTotal:function(todos) {
					return getMealsCostRecordTotal(todos);
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function mealsCostRecord_findPersonMealsCostRecord() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	var startYear = $('#startYear').val();
	var startMonth = $('#startMonth').val();
	var startDay = $('#startDay').val();
	var endYear = $('#endYear').val();
	var endMonth = $('#endMonth').val();
	var endDay = $('#endDay').val();
	var searchVal = $('#searchVal').val();
	var startTime = getStandardDay(startYear, startMonth, startDay);
	var endTime = getStandardDay(endYear, endMonth, endDay);
	
	if(!searchVal || searchVal=='') {
		alert('请输入姓名或身份证');
		return;
	}
	
	find_basic_by_json(path+'/mealsCostRecord/findPersonMealsCostRecord',
		{startDay: startTime, endDay: endTime, searchVal: searchVal}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function openDetail() {
	var year = $('#year').val();
	var month = $('#month').val();
	var day = $('#day').val();
	
	if(isEmpty(year)) {
		alert('请输入年');
		return;
	}
	if(isEmpty(month)) {
		alert('请选择月');
		return;
	}
	if(isEmpty(day)) {
		alert('请选择日');
		return;
	}
	day = getStandardDay(year, month, day);
	window.open('7-3-2rxjl_detail.html?day='+day);
}